package com.googlecode.dgwt.client.dijit.view.base;

import com.google.gwt.event.shared.GwtEvent;
import com.googlecode.dgwt.client.dijit.View;
import com.googlecode.dgwt.client.dijit.Widget;

/**
 * Base class for views that provides an external {@link Widget widget}.
 * 
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public abstract class ViewBase implements View {

    @Override
    public boolean equals(Object obj) {
        if (this == obj){
            return true;
        }
        if (obj instanceof View){
            obj = ((View) obj).getWidget();
        }
        return getWidget() == obj;
    }

    @Override
    public int hashCode() {
        return getWidget().hashCode();
    }

    @Override
    public void fireEvent(GwtEvent<?> event) {
        getWidget().fireEvent(event);
    }

    @Override
    public String getName() {
        return getWidget().getWidgetId();
    }

}
